package app.cn.com.school.fragment

import android.content.ContentValues
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import app.cn.com.school.R
import app.cn.com.school.activity.NewsActivity
import app.cn.com.school.activity.OrdersListActivity
import app.cn.com.school.activity.SearchActivity
import app.cn.com.school.activity.SortActivity
import app.cn.com.school.adapter.WeGoodsAdapter
import app.cn.com.school.adapter.WeStoreAdapter
import app.cn.com.school.adapter.WeTypeAdapter
import app.cn.com.school.databinding.FragmentWelfareBinding

/**
 * Created by Administrator on 2017/11/1 0001.
 */
class WelfareFragment : BaseFragment<FragmentWelfareBinding>() {
    override fun initBindingVar() {
    }

    var adapterType: WeTypeAdapter? = null
    var adapterGoods: WeGoodsAdapter? = null
    var adapterStore: WeStoreAdapter? = null
    var moreList = ArrayList<ContentValues>()
    private var mParam1: String? = null
    private var mParam2: String? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (arguments != null) {
            mParam1 = arguments.getString(ARG_PARAM1)
            mParam2 = arguments.getString(ARG_PARAM2)
        }
    }

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        initBinding(R.layout.fragment_welfare, container)
        mView = binding.root
        initView()
        return super.onCreateView(inflater, container, savedInstanceState)
    }


    private fun initView() {
        binding.titlebar.title.text = "福利社"
        binding.titlebar.back.visibility = View.GONE
        binding.titlebar.menuDate.visibility = View.VISIBLE
        binding.titlebar.menuDate.setImageResource(R.mipmap.used_news)
        binding.titlebar.liftText.visibility = View.VISIBLE
        binding.titlebar.liftText.setOnClickListener {
            startActivity(Intent(context, SortActivity::class.java).putExtra("type", "1"))
        }
        binding.titlebar.menuDate.setOnClickListener { startActivity(Intent(context, NewsActivity::class.java)) }
        binding.weTypeGrid.setOnItemClickListener { parent, view, position, id ->
            startActivity(Intent(context, SearchActivity::class.java).putExtra("type","1"))
        }


        moreList.add(ContentValues())
        moreList.add(ContentValues())
        moreList.add(ContentValues())
        moreList.add(ContentValues())

        if (adapterType == null) {
            adapterType = WeTypeAdapter(context, moreList)
            binding.weTypeGrid.adapter = adapterType
        }


        if (adapterGoods == null) {
            adapterGoods = WeGoodsAdapter(context, moreList)
            binding.weGoodsGrid.adapter = adapterGoods
        }

        if (adapterStore == null) {
            adapterStore = WeStoreAdapter(context, moreList)
            binding.weStore.adapter = adapterStore
        }

    }


    companion object {
        private val ARG_PARAM1 = "param1"
        private val ARG_PARAM2 = "param2"
        fun newInstance(param1: String, param2: String): WelfareFragment {
            val fragment = WelfareFragment()
            val args = Bundle()
            args.putString(ARG_PARAM1, param1)
            args.putString(ARG_PARAM2, param2)
            fragment.arguments = args
            return fragment
        }

    }

}